package com.cmcc.aregister.ui.adapter;

import com.cmcc.aregister.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AddressAdapter extends BaseAdapter {
    private Context context;
    public String[] first;
    public int checkPosition = 0;

    public AddressAdapter(Context context, String[] first) {
        this.context = context;
        this.first = first;
    }

    public int getCount() {
        return first.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(
                R.layout.a_address, null);
            holder.title = (TextView) convertView.findViewById(R.id.title);
            holder.tag = (ImageView) convertView.findViewById(R.id.tag);
            convertView.setTag(holder);
        }
        else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.title.setText(first[position]);
        if (position == checkPosition) {
            holder.tag.setVisibility(View.VISIBLE);
        }
        else {
            holder.tag.setVisibility(View.INVISIBLE);
        }
        return convertView;
    }

    static class ViewHolder {
        TextView title;
        ImageView tag;
    }
}